package eShopDemo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Cart implements Serializable {

	private static final long serialVersionUID = 1L;

	private List<Product> selectedProducts = new ArrayList<Product>();

	@ManagedProperty(value = "#{catalog}")
	private transient Catalog catalog;

	public Cart() {
		;
	}

	public List<Product> getSelectedProducts() {
		return selectedProducts;
	}

	public void setSelectedProducts(List<Product> selectedProducts) {
		this.selectedProducts = selectedProducts;
	}

	public Catalog getCatalog() {
		return catalog;
	}

	public void setCatalog(Catalog catalog) {
		this.catalog = catalog;
	}

	public void add(String pid) {
		Product product = catalog.findProductById(pid);
		if (product != null) {
			selectedProducts.add(product);
		}
	}

}
